<?php

namespace App\Kuafu\Banner\Model;

use App\Kuafu\Base\Model\Traits\KfSoftDeletes;
use App\Kuafu\User\Service\AuthService;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Kuafu\Base\Model\BaseModel;

class BannerModel extends BaseModel
{
    use HasFactory, KfSoftDeletes;

    protected $connection = 'mysql';
    protected $table      = 'banner_list';
    protected $primaryKey = 'id';
    protected $fillable   = [
        'configId',
        'image',
        'name',
        'url',
        'startTime',
        'endTime',
        'status',
        'createdByUid',
        'updatedByUid'
    ];

    protected $hidden = [
        'updatedAt',
        'isDeleted'
    ];

    /**
     * 删除【修改当前状态】
     *
     * @param int $id
     * @return int
     * @throws \App\Kuafu\User\Exceptions\UserException
     */
    public static function delData(int $id): int
    {
        return self::query()->where('id', $id)->update(['isDeleted' => 1, 'updatedByUid' => AuthService::getUserId()]);
    }

    /**
     * 修改
     *
     * @param int $id
     * @param array $data
     * @return int
     */
    public static function setData(int $id, array $data): int
    {
        return BannerModel::query()->where('id', $id)->update($data);
    }


}
